package bootstrap

import (
	v1 "shopstar/api/v1"
	"shopstar/core/cache"
	"shopstar/core/config"
	"shopstar/core/log"
	"shopstar/global"
	"shopstar/models"
	"time"
)

func init() {
	global.Viper = config.Viper(&global.Config, global.ConfigFile) // 监视配置文件是否发生变化
	InitCore()
	InitValidate("zh")
}

func InitCore() {
	if global.Config.Cache.Default == "freecache" {
		expira_at := time.Duration(global.Config.Cache.FreeCache.Expiration)
		cache.CacheManager = cache.NewCache(cache.NewFreeCache(global.Config.Cache.FreeCache.CacheSize, expira_at))
	}
	// 路由加载
	v1.InitRouter()
	// 加载模型
	models.InitDb(&global.Config)
	// 日志加载
	global.Logs = log.InitLogger(&global.Config)
}
